/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.examinate.extheory.user.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.app.mockexam.theory.user.entity.TmockexamTheoryUser;
import com.jeesite.modules.conf.AppController;
import com.jeesite.modules.conf.MessageCode;
import com.jeesite.modules.zx.examination.barbecue.user.entity.TexaminationBarbecueUser;
import com.jeesite.modules.zx.examination.barbecue.user.service.TexaminationBarbecueUserService;

/**
 * 理论考试用户记录表Controller
 * @author zpp
 * @version 2020-03-07
 */
@Controller
@RequestMapping(value = "/app/examination/barbecue/user/")
public class AppExaminationBarbecueUserController {

	@Autowired
	private TexaminationBarbecueUserService texaminationBarbecueUserService;
	@PostMapping(value = "save")
	public void save(TexaminationBarbecueUser entity,HttpServletRequest request,HttpServletResponse response) {
		String theoryId = entity.getTheoryId();
		if(StringUtils.isBlank(theoryId)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "理论记录标识");
			return;
		}
		String userId=entity.getUserId();
		if(StringUtils.isBlank(userId)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "用户标识");
			return;
		}
		String postId = entity.getPostId();
		if(StringUtils.isBlank(postId)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "岗位标识");
			return;
		}
		List<TexaminationBarbecueUser> findList = texaminationBarbecueUserService.findList(entity);
		if(findList!=null&&findList.size()>0){
			entity = findList.get(0);			
		}else{
			entity.setType(1);
			texaminationBarbecueUserService.save(entity);
		}
		JSONObject json=JSONObject.parseObject(JsonMapper.toJson(entity));
		AppController.renderSuccessObject(response, json, MessageCode.SUCCESS_ACK);
		return;
	}
	
	
}